﻿/*============================================================================*/
/*                  Vkinging Electronics / Data Acquisition                   */
/*----------------------------------------------------------------------------*/
/*     Copyright (c)  ShenZhen Vkinging 2013-2025.  All Rights Reserved.      */
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Title:       libvkdaq.h                                                    */
/* Purpose:     Include file for VK-DAQ library support.                      */
/*                                                                            */
/*============================================================================*/




#ifndef LIBVKDAQ_H
#define LIBVKDAQ_H

#ifndef LIBVKDAQ_API
	#ifdef _WIN32
		#ifdef LIBVKDAQ_EXPORTS
			#define LIBVKDAQ_API __declspec(dllexport)
		#else
			#define LIBVKDAQ_API __declspec(dllimport)
		#endif
	#elif defined(__linux__)
		#ifdef LIBVKDAQ_EXPORTS
			#define LIBVKDAQ_API __attribute__((visibility("default")))
		#else
			#define LIBVKDAQ_API
		#endif
	#endif
#endif // LIBVKDAQ_H

#if defined(__linux__) || defined(__APPLE__)
#define VK_API
#define VK_API_C
#define VK_CALLBACK
#else
#define VK_API                 __stdcall
#define VK_API_C               __cdecl
#define VKDAQCALLBACK          __cdecl
#endif // defined(__linux__) || defined(__APPLE__)

#ifndef _VK_int8_DEFINED_
#define _VK_int8_DEFINED_
typedef signed char        int8;
#endif // _VK_int8_DEFINED_

#ifndef _VK_uInt8_DEFINED_
#define _VK_uInt8_DEFINED_
typedef unsigned char      uInt8;
#endif // _VK_uInt8_DEFINED_

#ifndef _VK_int16_DEFINED_
#define _VK_int16_DEFINED_
typedef signed short       int16;
#endif // _VK_int16_DEFINED_

#ifndef _VK_uInt16_DEFINED_
#define _VK_uInt16_DEFINED_
typedef unsigned short     uInt16;
#endif // _VK_uInt16_DEFINED_

#ifndef _VK_int32_DEFINED_
#define _VK_int32_DEFINED_
typedef long				int32;
#endif // _VK_int32_DEFINED_

#ifndef _VK_uInt32_DEFINED_
#define _VK_uInt32_DEFINED_
typedef unsigned long      uInt32;
#endif // _VK_uInt32_DEFINED_

#ifndef _VK_float32_DEFINED_
#define _VK_float32_DEFINED_
typedef float              float32;
#endif // _VK_float32_DEFINED_

#ifndef _VK_float64_DEFINED_
#define _VK_float64_DEFINED_
typedef double             float64;
#endif // _VK_float64_DEFINED_

#ifndef _VK_int64_DEFINED_
#define _VK_int64_DEFINED_
#if defined(__linux__) || defined(__APPLE__)
typedef long long int      int64;
#else
typedef __int64            int64;
#endif // defined(__linux__) || defined(__APPLE__)
#endif // _VK_int64_DEFINED_

#ifndef _VK_uInt64_DEFINED_
#define _VK_uInt64_DEFINED_
#if defined(__linux__) || defined(__APPLE__)
typedef unsigned long long uInt64;
#else
typedef unsigned __int64   uInt64;
#endif // defined(__linux__) || defined(__APPLE__)
#endif // _VK_uInt64_DEFINED_

typedef const char* TaskHandle;

#define VkDaq_Val_SingleEnded				(0)
#define VkDaq_Val_Differential				(1)

// Values for Vkdaq_AI_Voltage_Units
#define VkDaq_Val_Volts						(0)
#define VkDaq_Val_Millivolt					(1)
#define VkDaq_Val_CustomUnit				(2)

// Values for Vkdaq_AI_Current_Units
#define VkDaq_Val_Amperes					(0)
#define VkDaq_Val_Milliampere				(1)
#define VkDaq_Val_CustomUnit				(2)

// Values for Vkdaq_AI_Accel_Charge_Sensitivity_Units
#define VkDaq_Val_AccelUnit_g               (0)
#define VkDaq_Val_MetersPerSecondSquared    (1)
#define VkDaq_Val_InchesPerSecondSquared    (2)
#define VkDaq_Val_FromCustomScale           (3)

#define DAQmx_Val_SignalType_IEPE           (0)
#define DAQmx_Val_SignalType_PE             (1)

#define VkDaq_Val_Falling					(0)
#define VkDaq_Val_Rising					(1)
#define VkDaq_Val_LowLevel					(2)
#define VkDaq_Val_HighLevel					(3)

#define VkDaq_Val_ClkSrc_OnBoardClk			(0)
#define VkDaq_Val_ClkSrc_SyncPluse			(1)
#define VkDaq_Val_ClkSrc_MasterSlaves		(2)

#define VkDaq_Val_ContSamps					(0)
#define VkDaq_Val_FiniteSamps				(1)

#define VkDaq_Val_GroupByScanNumber         (0)
#define VkDaq_Val_GroupByChannel			(1)

#define VkDaq_Val_DeviceNotifyType_Added		(0)
#define VkDaq_Val_DeviceNotifyType_Removed		(1)

#define VkDaq_Val_ConfigCallback ("ConfigCallback")

#define VkDaqSuccess                        (0)
#define VkDaqFailed(error)                  ((error)<0)

#include <stdint.h>

typedef int32_t(*config_callback_t)();
typedef void(*device_notify_callback_t)(const char* notifyDevice, int32_t notifyType);

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

	LIBVKDAQ_API int32_t VkDaqGetTasks(char tasks[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqCreateTask(const char* task);
	LIBVKDAQ_API int32_t VkDaqClearTask(const char* task);
	LIBVKDAQ_API int32_t VkDaqStartTask(const char* task);
	LIBVKDAQ_API int32_t VkDaqStopTask(const char* task);

	LIBVKDAQ_API int32_t VkDaqGetTaskAttribute(const char* task, const char* attrName, char attrValue[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqSetTaskAttribute(const char* task, const char* attrName, const char* attrValue);

	LIBVKDAQ_API int32_t VkDaqGetTaskData(const char* task, double dat[], int32_t sampsPerChan, int32_t fillmode, double timeout);
	LIBVKDAQ_API int32_t VkDaqSetTaskData(const char* task, const double dat[], int32_t sampsPerChan, int32_t fillmode, int32_t autoStart, double timeout);

	LIBVKDAQ_API int32_t VkDaqAddDevice(const char* dev);
	LIBVKDAQ_API int32_t VkDaqGetDevices(char devsAddress[], char devsName[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqSetDeviceNotifyCallback(device_notify_callback_t callback);
	LIBVKDAQ_API int32_t VkDaqGetChannels(const char* dev, char channels[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqGetDeviceAttribute(const char* dev, const char* attrName, char attrValue[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqSetDeviceAttribute(const char* dev, const char* attrName, const char* attrValue);
	LIBVKDAQ_API int32_t VkDaqGetChannelAttribute(const char* chan, const char* attrName, char attrValue[], int32_t size);
	LIBVKDAQ_API int32_t VkDaqSetChannelAttribute(const char* chan, const char* attrName, const char* attrValue);

	LIBVKDAQ_API int32_t VkDaqCreateAIVoltageChan(const char* task, const char* chans, const char* reserved1, int32_t terminalConfig, double minVal, double maxVal, int32_t units, const char* reserved2);
	LIBVKDAQ_API int32_t VkDaqCreateAICurrentChan(const char* task, const char* chans, const char* reserved1, int32_t terminalConfig, double minVal, double maxVal, int32_t units, const char* reserved2);
	LIBVKDAQ_API int32_t VkDaqCreateAIAccelChan(const char* task, const char* chans, const char* reserved1, int32_t terminalConfig, double minVal, double maxVal, int32_t units, double sensitivity, int32_t signalType, const char* reserved2);
	LIBVKDAQ_API int32_t VkDaqCreateDIChan(const char* task, const char* chans, const char* reserved1, uint32_t mask);
	LIBVKDAQ_API int32_t VkDaqCreateMIChan(const char* task, const char* chans, const char* reserved1, const char* source, uint32_t maxVal);

	LIBVKDAQ_API int32_t VkDaqCreateAOVoltageChan(const char* task, const char* chans, const char* reserved1, double minVal, double maxVal, int32_t units, const char* reserved2);

	LIBVKDAQ_API int32_t VkDaqCfgSampClkTiming(const char* task, int32_t source, double samplingFrequency, int32_t reserved, int32_t sampleMode, int32_t sampsPerChanToAcquire);

	LIBVKDAQ_API int32_t VkDaqCfgDigEdgeRefTrig(const char* task, const char* triggerSource, int32_t triggerEdge, uint32_t reserved);
	LIBVKDAQ_API int32_t VkDaqCfgAnlgEdgeRefTrig(const char* task, const char* triggerSource, int32_t triggerEdge, double triggerLevel, uint32_t reserved);
	
	LIBVKDAQ_API int32_t VkDaqAssistantDisplay(const char* tray, const char* toast);

	LIBVKDAQ_API const char* VkDaqGetLastErrorInfo(void);

	static inline const char* CONFIG_CALLBACK(config_callback_t cb) { return (const char*) (uintptr_t) (cb); }
	
	
#ifdef __cplusplus
};
#endif // __cplusplus

#endif // LIBVKDAQ_H



